require("lib/functions")
require("lib/classes")
require("lib/perPixel")

function love.load()
	love.graphics.setBackgroundColor( 150, 150, 150 )
	sheet = love.graphics.newImage( "img/omegasectortiles.png" )
	bg = love.graphics.newImage( "img/SkyBackground.jpg" )
	
	map = loadMap()
	tiles = loadTiles( map )
	mapCanvas = loadCanvas( map, sheet, tiles )
	
	map["offsetX"] = 0
	map["offsetY"] = 0
	
	player = Player.new(100, 100)
	love.graphics.setLineWidth( 10 )
end

function love.update(dt)
	if love.keyboard.isDown( "a" ) then player.setVelX( -100 ) end
	if love.keyboard.isDown( "d" ) then player.setVelX( 100 ) end
	if love.keyboard.isDown( "w" ) then player.setVelY( -100 ) end
	if love.keyboard.isDown( "s" ) then player.setVelY( 100 ) end
	
	player:update(dt)
	
	tile = map.layers[1].data[player.getTileX()][player.getTileY()]
	collide = perPixelCollision( player, tile, tiles )
	
end

function love.draw()
	love.graphics.draw( bg, 0, 0, 0, 2, 1.2 )
	love.graphics.draw( mapCanvas, math.floor(map.offsetX), math.floor(map.offsetY) )
	love.graphics.print("FPS: " .. love.timer.getFPS(), 960, 10)
	--love.graphics.print("collide: " .. tostring(collide), 10, 500)
	love.graphics.print("x: " .. player.getTileX(), 10, 700)
	love.graphics.print("y: " .. player.getTileY(), 10, 720)
	
	
	player:draw()
end

function love.mousepressed(x, y, button)
end

function love.focus(f) 
	gameIsPaused = not f 
end